<?php
/**
 * Created by PhpStorm.
 * User: DaibiDaddy
 * Date: 2016/6/3
 * Time: 14:59
 */

namespace App\Setting;

use App\Base\BaseForm;
use App\Base\ViewsInList;
use App\Model\LazyCommon\CCM;
use App\Model\TopicModel;

class VideoSetting{

    /*手动获取的配置项*/
    public $catType = "level";//Options:level snake
    public $entityCnName = "课时";//模块名称
    public $table = "Video";//数据表名称
    public $editKeys = array('id','title','topic_Id','pic','grade_Id','subject_Id','orders','addtime','updatetime','isHot','isVip','isScan','tips','url','teacher_Id','isOn');//后台管理列表中可以直接编辑的字段
    public $perPage = 1000;//后台管理列表中可以直接编辑的字段

    /*自动获取的配置项*/
    public $bundleName;
    public $entityName;
    public $SettingPath;
    public $entityPath;
    public $entity;
    public $modelPath;
    public $doctrine;
    public $em;

    public function __construct($doctrine)
    {
        $this->bundleName = "App";
        $this->entityName = str_replace("\\","",str_replace("Setting","",str_replace(__NAMESPACE__,"",__CLASS__)));
        $this->SettingPath = __CLASS__;
        //$this->entityPath = str_replace($this->entityName."Entity",$this->entityName,str_replace("Setting","Entity",__CLASS__));
        $this->entityPath = "App\\Entity\\".$this->entityName;
        $this->entity = new $this->entityPath();
        $this->modelPath = str_replace("Setting","Model",__CLASS__);
        $this->doctrine = $doctrine;
        $this->em = $doctrine->getManager();
    }

    public function listConfig()
    {
        $default = array();
        $default["Video AS Video"]["select"] = array('id','title','star','topic_Id','pic','grade_Id','subject_Id','orders','addtime','updatetime','is_Hot','is_Vip','is_Scan','tips','url','teacher_Id','is_On');
        $default["Video AS Video"]["search"] = array('id','title','star','topic_Id','pic','grade_Id','subject_Id','orders','addtime','updatetime','is_Hot','is_Vip','is_Scan','tips','url','teacher_Id','is_On');
        $default["Video AS Video"]["condition"] = array('id','title','star','topic_Id','pic','grade_Id','subject_Id','orders','addtime','updatetime','is_Hot','is_Vip','is_Scan','tips','url','teacher_Id','is_On');
        $default["Video AS Video"]["orderBy"] = array("orders"=>"ASC");

        $join = array();
        $join["Topic AS Topic"]["on"] = "Topic.id = topic_Id";
        $join["Topic AS Topic"]["select"] = array();
        $join["Topic AS Topic"]["search"] = array();
        $join["Topic AS Topic"]["condition"] = array();
        $join["Topic AS Topic"]["orderBy"] = array();

        return array(
            "default"   => $default,
            "joins"     => $join,
        );
    }

    public function viewConfig()
    {

    }


    public function formConfig()
    {
        $BaseForm = new BaseForm();

        $TopicModel = new TopicModel($this->doctrine);
        $data = $TopicModel->getAll();
        $CCM = new CCM($this->doctrine);
        $topics = $CCM->createSelectFromEntity($data,"title");

        $config["topicId"] = $BaseForm->select("topicId","专题",$topics)->disable();
        $config["title"] = $BaseForm->text("title","标题");
        $config["pic"] = $BaseForm->pic("pic","封面图");
        $config["url"] = $BaseForm->textarea("url","视频地址");
//        $config["gradeId"] = $BaseForm->text("gradeId","gradeid");
//        $config["subjectId"] = $BaseForm->text("subjectId","subjectid");
        $config["star"] = $BaseForm->text("star","课程难度");
        $config["orders"] = $BaseForm->text("orders","课时序号");
        $config["tips"] = $BaseForm->text("tips","备注");
//        $config["addtime"] = $BaseForm->text("addtime","创建时间");
//        $config["updatetime"] = $BaseForm->text("updatetime","updatetime");
        $isHotData[0] = "否";
        $isHotData[1] = "是";
        $config["isHot"] = $BaseForm->radio("isHot","热门课时",$isHotData);
        $isVipData[0] = "否";
        $isVipData[1] = "是";
        $config["isVip"] = $BaseForm->radio("isVip","会员特权",$isVipData);
        $isScanData[0] = "否";
        $isScanData[1] = "是";
        $config["isScan"] = $BaseForm->radio("isScan","允许试听",$isScanData);
//        $config["teacherId"] = $BaseForm->text("teacherId","teacherid");
        $isOnData[0] = "否";
        $isOnData[1] = "是";
        $config["isOn"] = $BaseForm->radio("isOn","上线观看",$isOnData);
        return $config;
    }
}